<template>
  <div class="app-container">
    <el-card class="filter-container" shadow="never">
      <div>
        <el-button style="float:right" type="primary" @click="handleSearchList()" size="mini">
          查询搜索
        </el-button>
        <el-button style="float:right;margin-right: 15px" @click="handleResetSearch()" size="mini">
          重置
        </el-button>
      </div>
      <div>
        <el-form :inline="true" :model="listQuery" size="mini" label-width="100px">
          <el-form-item label="手机号：">
            <el-input v-model="listQuery.phoneNo" class="input-width" placeholder="请输入手机号" clearable></el-input>
          </el-form-item>
          <el-form-item label="登录结果：">
              <el-select v-model="listQuery.state" placeholder="请选择登录结果">
                <el-option
                  v-for="item in loginOptions"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
          </el-form-item>
          <el-form-item label="登录IP：">
            <el-input v-model="listQuery.ip" class="input-width" placeholder="请输入登录IP" clearable></el-input>
          </el-form-item>
        </el-form>
      </div>
    </el-card>
    <el-card class="operate-container" shadow="never">
      <i class="el-icon-tickets"></i>
      <span>通知列表</span>
    </el-card>
    <div class="table-container log-container">
      <el-table ref="adminTable" size="mini" :data="list" style="width: 100%;" v-loading="listLoading" border>
         <el-table-column label="ID" width="80" align="center">
          <template slot-scope="scope">{{ scope.row.id }}</template>
        </el-table-column>
        <el-table-column label="手机号" width="140"   align="center">
          <template slot-scope="scope">{{ scope.row.phoneNo }}</template>
        </el-table-column>
         <el-table-column label="登录IP" width="140"  align="center">
          <template slot-scope="scope">{{ scope.row.ip }}</template>
        </el-table-column>
        <el-table-column label="位置"  align="center">
          <template slot-scope="scope">{{ scope.row.address }}</template>
        </el-table-column>
        <el-table-column label="说明"  align="center">
          <template slot-scope="scope">{{ scope.row.remark }}</template>
        </el-table-column>
        <el-table-column label="登录时间" width="220" align="center">
          <template slot-scope="scope">{{ scope.row.createTime | formatDateTime }}</template>
        </el-table-column>
        <el-table-column label="登录环境"  align="center">
          <template slot-scope="scope">{{ scope.row.userAgent }}</template>
        </el-table-column>
      </el-table>
    </div>
    <div class="pagination-container">
      <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange"
        layout="total, sizes,prev, pager, next,jumper" :current-page.sync="listQuery.pageNum"
        :page-size="listQuery.pageSize" :page-sizes="[5, 10, 15, 20]" :total="total">
      </el-pagination>
    </div>

 

  </div>
</template>
<script>
import { getLoginLog } from '@/api/commons';
import { formatDate } from '@/utils/date';
import { createNamespacedHelpers } from "vuex";
const { mapState } = createNamespacedHelpers("umsLog");
const defaultListQuery = {
  pageNum: 1,
  pageSize: 10,
  phoneNo: null,
  ip:null,
  state:''
};
export default {

   computed: {
    ...mapState({
      loginOptions: state => [...[{ label: '全部', value: '' }], ...state.routes.loginOptions]
    })
  },
  data() {
    return {
      listLoading:false,
      listQuery: Object.assign({}, defaultListQuery),
      list: null,
      total: null,
    }
  },
  created() {
    this.getList();
  },
  filters: {
    formatDateTime(time) {
      if (time == null || time === '') {
        return 'N/A';
      }
      let date = new Date(time);
      return formatDate(date, 'yyyy-MM-dd hh:mm:ss')
    }
  },
  methods: {
    handleResetSearch() {
      this.listQuery = Object.assign({}, defaultListQuery);
      this.getList();
    },
    handleSearchList() {
      this.listQuery.pageNum = 1;
      this.getList();
    },
    handleSizeChange(val) {
      this.listQuery.pageNum = 1;
      this.listQuery.pageSize = val;
      this.getList();
    },
    handleCurrentChange(val) {
      this.listQuery.pageNum = val;
      this.getList();
    },

    getList() {
      this.listLoading = true;
      getLoginLog(this.listQuery).then(response => {
        this.listLoading = false;
        this.list = response.data.list;
        this.total = response.data.total;
      });
    }

   
  }
}
</script>
<style lang="scss">
.log-container{
 height: calc(100vh - 242px);
  .el-table__body-wrapper{
    height: calc(100vh - 295px);
    overflow: auto;
  }
}
</style>